package com.zecan.blog.security.handler;

import cn.hutool.json.JSONUtil;
import com.zecan.blog.common.status.UserStatus;
import com.zecan.blog.controller.exception.UserException;
import com.zecan.blog.utils.BlogResultUtils;
import lombok.SneakyThrows;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 登出处理
 * @author zecan
 * @Description:
 * @ClassName: JwtLogoutHandler
 * @date 2022/12/29 13:15
 */
@Component
public class JwtLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication)   {
        // 用户如果存在验证的信息  保存在SecurityContextHolder中,则进行security登出，删除权限信息
        if(authentication != null) {
             new SecurityContextLogoutHandler().logout(request, response, authentication);
        }
    }
}
